2 if(!defined('sugarEntry'))define('sugarEntry', true);
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
39 if (version_compare(phpversion(),'5.2.0') < 0) {
40 $msg = 'Minimum PHP version required is 5.2.0. You are using PHP version '. phpversion();
43 $session_id = session_id();
44 if(empty($session_id)){
47 $GLOBALS['installing'] = true;
48 define('SUGARCRM_IS_INSTALLING', $GLOBALS['installing']);
49 $GLOBALS['sql_queries'] = 0;
50 require_once('include/SugarLogger/LoggerManager.php');
51 require_once('sugar_version.php');
52 require_once('include/utils.php');
53 require_once('install/install_utils.php');
54 require_once('install/install_defaults.php');
55 require_once('include/TimeDate.php');
56 require_once('include/Localization/Localization.php');
57 require_once('include/SugarTheme/SugarTheme.php');
58 require_once('include/utils/LogicHook.php');
59 require_once('data/SugarBean.php');
60 require_once('include/entryPoint.php');
61 //check to see if the script files need to be rebuilt, add needed variables to request array
62 $_REQUEST['root_directory'] = getcwd();
63 $_REQUEST['js_rebuild_concat'] = 'rebuild';
64 require_once('jssource/minify.php');
66 $timedate = TimeDate::getInstance();
67 // cn: set php.ini settings at entry points
69 $locale = new Localization();
71 if(get_magic_quotes_gpc() == 1) {
72 $_REQUEST = array_map("stripslashes_checkstrings", $_REQUEST);
73 $_POST = array_map("stripslashes_checkstrings", $_POST);
74 $_GET = array_map("stripslashes_checkstrings", $_GET);
78 $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
79 $setup_sugar_version = $sugar_version;
80 $install_script = true;
82 ///////////////////////////////////////////////////////////////////////////////
83 //// INSTALL RESOURCE SETUP
84 $css = 'install/install.css';
85 $icon = 'include/images/sugar_icon.ico';
86 $sugar_md = 'include/images/sugar_md_open.png';
87 $loginImage = 'include/images/sugarcrm_login.png';
88 $common = 'install/installCommon.js';
90 ///////////////////////////////////////////////////////////////////////////////
91 //// INSTALLER LANGUAGE
95 function getSupportedInstallLanguages(){
96 $supportedLanguages = array(
97 'en_us' => 'English (US)',
99 if(file_exists('install/lang.config.php')){
100 include('install/lang.config.php');
101 if(!empty($config['languages'])){
103 foreach($config['languages'] as $k=>$v){
104 if(file_exists('install/language/' . $k . '.lang.php')){
105 $supportedLanguages[$k] = $v;
110 return $supportedLanguages;
112 $supportedLanguages = getSupportedInstallLanguages();
120 // after install language is selected, use that pack
121 $default_lang = 'en_us';
122 if(!isset($_POST['language']) && (!isset($_SESSION['language']) && empty($_SESSION['language']))) {
123 if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
124 $lang = parseAcceptLanguage();
125 if(isset($supportedLanguages[$lang])) {
126 $_POST['language'] = $lang;
128 $_POST['language'] = $default_lang;
133 if(isset($_POST['language'])) {
134 $_SESSION['language'] = str_replace('-','_',$_POST['language']);
137 $current_language = isset($_SESSION['language']) ? $_SESSION['language'] : $default_lang;
139 if(file_exists("install/language/{$current_language}.lang.php")) {
140 require_once("install/language/{$current_language}.lang.php");
142 require_once("install/language/{$default_lang}.lang.php");
145 if($current_language != 'en_us') {
146 $my_mod_strings = $mod_strings;
147 include('install/language/en_us.lang.php');
148 $mod_strings = sugarArrayMerge($mod_strings, $my_mod_strings);
150 //// END INSTALLER LANGUAGE
151 ///////////////////////////////////////////////////////////////////////////////
153 //get the url for the helper link
154 $help_url = get_help_button_url();
158 //if this license print, then redirect and exit,
159 if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'licensePrint')
161 include('install/licensePrint.php');
165 //check to see if mysqli is enabled
166 if(function_exists('mysqli_connect')){
167 $_SESSION['mysql_type'] = 'mysqli';
170 //if this is a system check, then just run the check and return,
171 //this is an ajax call and there is no need for further processing
172 if(isset($_REQUEST['checkInstallSystem']) && ($_REQUEST['checkInstallSystem'])){
173 require_once('install/installSystemCheck.php');
174 echo runCheck($install_script, $mod_strings);
178 //if this is a DB Settings check, then just run the check and return,
179 //this is an ajax call and there is no need for further processing
180 if(isset($_REQUEST['checkDBSettings']) && ($_REQUEST['checkDBSettings'])){
181 require_once('install/checkDBSettings.php');
182 echo checkDBSettings();
186 //maintaining the install_type if earlier set to custom
187 if(isset($_REQUEST['install_type']) && $_REQUEST['install_type'] == 'custom'){
188 $_SESSION['install_type'] = $_REQUEST['install_type'];
191 //set the default settings into session
192 foreach($installer_defaults as $key =>$val){
193 if(!isset($_SESSION[$key])){
194 $_SESSION[$key] = $val;
199 clean_special_arguments();
200 print_debug_comment();
201 $next_clicked = false;
204 // use a simple array to map out the steps of the installer page flow
205 $workflow = array( 'welcome.php',
210 $workflow[] = 'systemOptions.php';
211 $workflow[] = 'dbConfig_a.php';
212 //$workflow[] = 'dbConfig_b.php';
214 //define web root, which will be used as default for site_url
215 if($_SERVER['SERVER_PORT']=='80'){
216 $web_root = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
218 $web_root = $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['PHP_SELF'];
220 $web_root = str_replace("/install.php", "", $web_root);
221 $web_root = "http://$web_root";
223 if(!isset($_SESSION['oc_install']) || $_SESSION['oc_install'] == false) {
224 $workflow[] = 'siteConfig_a.php';
225 if(isset($_SESSION['install_type']) && !empty($_SESSION['install_type']) && $_SESSION['install_type']=='custom'){
226 $workflow[] = 'siteConfig_b.php';
229 if(is_readable('config.php')) {
230 require_once('config.php');
234 // set the form's php var to the loaded config's var else default to sane settings
235 if(!isset($_SESSION['setup_site_url']) || empty($_SESSION['setup_site_url'])){
236 if(isset($sugar_config['site_url']) && !empty($sugar_config['site_url'])){
237 $_SESSION['setup_site_url']= $sugar_config['site_url'];
239 $_SESSION['setup_site_url']= $web_root;
242 if(!isset($_SESSION['setup_system_name']) || empty($_SESSION['setup_system_name'])){$_SESSION['setup_system_name'] = 'SugarCRM';}
243 if(!isset($_SESSION['setup_site_session_path']) || empty($_SESSION['setup_site_session_path'])){$_SESSION['setup_site_session_path'] = (isset($sugar_config['session_dir'])) ? $sugar_config['session_dir'] : '';}
244 if(!isset($_SESSION['setup_site_log_dir']) || empty($_SESSION['setup_site_log_dir'])){$_SESSION['setup_site_log_dir'] = (isset($sugar_config['log_dir'])) ? $sugar_config['log_dir'] : '.';}
245 if(!isset($_SESSION['setup_site_guid']) || empty($_SESSION['setup_site_guid'])){$_SESSION['setup_site_guid'] = (isset($sugar_config['unique_key'])) ? $sugar_config['unique_key'] : '';}
249 $workflow[] = 'confirmSettings.php';
250 $workflow[] = 'performSetup.php';
252 if(!isset($_SESSION['oc_install']) || $_SESSION['oc_install'] == false){
253 if(isset($_SESSION['install_type']) && !empty($_SESSION['install_type']) && $_SESSION['install_type']=='custom'){
254 //$workflow[] = 'download_patches.php';
255 $workflow[] = 'download_modules.php';
259 $workflow[] = 'register.php';
262 // increment/decrement the workflow pointer
263 if(!empty($_REQUEST['goto'])) {
264 switch($_REQUEST['goto']) {
265 case $mod_strings['LBL_CHECKSYS_RECHECK']:
266 $next_step = $_REQUEST['current_step'];
268 case $mod_strings['LBL_BACK']:
269 $next_step = $_REQUEST['current_step'] - 1;
271 case $mod_strings['LBL_NEXT']:
272 case $mod_strings['LBL_START']:
273 $next_step = $_REQUEST['current_step'] + 1;
274 $next_clicked = true;
276 case 'SilentInstall':
284 // Add check here to see if a silent install config file exists; if so then launch silent installer
285 elseif ( is_file('config_si.php') && empty($sugar_config['installer_locked'])) {
287 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
290 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
291 <meta http-equiv="Content-Style-Type" content="text/css">
292 <meta http-equiv="Refresh" content="1; url=install.php?goto=SilentInstall&cli=true">
293 <title>{$mod_strings['LBL_WIZARD_TITLE']} {$mod_strings['LBL_TITLE_WELCOME']} {$setup_sugar_version} {$mod_strings['LBL_WELCOME_SETUP_WIZARD']}</title>
294 <link REL="SHORTCUT ICON" HREF="{$icon}">
295 <link rel="stylesheet" href="{$css}" type="text/css">
298 <table cellspacing="0" cellpadding="0" border="0" align="center" class="shell">
300 <td colspan="2" id="help"><a href="{$help_url}" target='_blank'>{$mod_strings['LBL_HELP']} </a></td></tr>
304 <img src="{$sugar_md}" alt="SugarCRM" border="0">
306 {$mod_strings['LBL_TITLE_WELCOME']} {$setup_sugar_version} {$mod_strings['LBL_WELCOME_SETUP_WIZARD']}</th>
308 <th width="200" height="30" style="text-align: right;"><a href="http://www.sugarcrm.com" target="_blank"><IMG src="{$loginImage}" width="145" height="30" alt="SugarCRM" border="0"></a>
312 <td colspan="2" id="ready_image"><IMG src="include/images/install_themes.jpg" width="698" height="247" alt="Sugar Themes" border="0"></td>
316 <td colspan="2" id="ready">{$mod_strings['LBL_LAUNCHING_SILENT_INSTALL']} </td>
327 $exclude_files = array('register.php','download_modules.php');
329 if(isset($next_step) && isset($workflow[$next_step]) && !in_array($workflow[$next_step],$exclude_files) && isset($sugar_config['installer_locked']) && $sugar_config['installer_locked'] == true) {
330 $the_file = 'installDisabled.php';
331 $disabled_title = $mod_strings['LBL_DISABLED_DESCRIPTION'];
332 $disabled_title_2 = $mod_strings['LBL_DISABLED_TITLE_2'];
333 $disabled_text =<<<EOQ
334 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION']}</p>
336 'installer_locked' => false,
338 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION_2']}</p>
340 <p>{$mod_strings['LBL_DISABLED_HELP_1']} <a href="{$mod_strings['LBL_DISABLED_HELP_LNK']}" target="_blank">{$mod_strings['LBL_DISABLED_HELP_2']}</a>.</p>
344 $validation_errors = array();
345 // process the data posted
347 // store the submitted data because the 'Next' button was clicked
348 switch($workflow[trim($_REQUEST['current_step'])]) {
350 $_SESSION['language'] = $_REQUEST['language'];
351 $_SESSION['setup_site_admin_user_name'] = 'admin';
354 $_SESSION['setup_license_accept'] = get_boolean_from_request('setup_license_accept');
355 $_SESSION['license_submitted'] = true;
358 // eventually default all vars here, with overrides from config.php
359 if(is_readable('config.php')) {
360 global $sugar_config;
361 include_once('config.php');
364 $default_db_type = 'mysql';
366 if(!isset($_SESSION['setup_db_type'])) {
367 $_SESSION['setup_db_type'] = empty($sugar_config['dbconfig']['db_type']) ? $default_db_type : $sugar_config['dbconfig']['db_type'];
371 case 'installType.php':
372 $_SESSION['install_type'] = $_REQUEST['install_type'];
373 if(isset($_REQUEST['setup_license_key']) && !empty($_REQUEST['setup_license_key'])){
374 $_SESSION['setup_license_key'] = $_REQUEST['setup_license_key'];
376 $_SESSION['licenseKey_submitted'] = true;
382 case 'systemOptions.php':
383 $_SESSION['setup_db_type'] = $_REQUEST['setup_db_type'];
384 $validation_errors = validate_systemOptions();
385 if(count($validation_errors) > 0) {
390 case 'dbConfig_a.php':
391 //validation is now done through ajax call to checkDBSettings.php
392 if(isset($_REQUEST['setup_db_drop_tables'])){
393 $_SESSION['setup_db_drop_tables'] = $_REQUEST['setup_db_drop_tables'];
394 if($_SESSION['setup_db_drop_tables']=== true || $_SESSION['setup_db_drop_tables'] == 'true'){
395 $_SESSION['setup_db_create_database'] = false;
400 case 'siteConfig_a.php':
401 if(isset($_REQUEST['setup_site_url'])){$_SESSION['setup_site_url'] = $_REQUEST['setup_site_url'];}
402 if(isset($_REQUEST['setup_system_name'])){$_SESSION['setup_system_name'] = $_REQUEST['setup_system_name'];}
403 $_SESSION['setup_site_admin_user_name'] = $_REQUEST['setup_site_admin_user_name'];
404 $_SESSION['setup_site_admin_password'] = $_REQUEST['setup_site_admin_password'];
405 $_SESSION['setup_site_admin_password_retype'] = $_REQUEST['setup_site_admin_password_retype'];
406 $_SESSION['siteConfig_submitted'] = true;
408 $validation_errors = array();
409 $validation_errors = validate_siteConfig('a');
410 if(count($validation_errors) > 0) {
414 case 'siteConfig_b.php':
415 $_SESSION['setup_site_sugarbeet_automatic_checks'] = get_boolean_from_request('setup_site_sugarbeet_automatic_checks');
417 $_SESSION['setup_site_custom_session_path'] = get_boolean_from_request('setup_site_custom_session_path');
418 if($_SESSION['setup_site_custom_session_path']){
419 $_SESSION['setup_site_session_path'] = $_REQUEST['setup_site_session_path'];
421 $_SESSION['setup_site_session_path'] = '';
424 $_SESSION['setup_site_custom_log_dir'] = get_boolean_from_request('setup_site_custom_log_dir');
425 if($_SESSION['setup_site_custom_log_dir']){
426 $_SESSION['setup_site_log_dir'] = $_REQUEST['setup_site_log_dir'];
428 $_SESSION['setup_site_log_dir'] = '.';
431 $_SESSION['setup_site_specify_guid'] = get_boolean_from_request('setup_site_specify_guid');
432 if($_SESSION['setup_site_specify_guid']){
433 $_SESSION['setup_site_guid'] = $_REQUEST['setup_site_guid'];
435 $_SESSION['setup_site_guid'] = '';
437 $_SESSION['siteConfig_submitted'] = true;
438 if(isset($_REQUEST['setup_site_sugarbeet_anonymous_stats'])){
439 $_SESSION['setup_site_sugarbeet_anonymous_stats'] = get_boolean_from_request('setup_site_sugarbeet_anonymous_stats');
441 $_SESSION['setup_site_sugarbeet_anonymous_stats'] = 0;
444 $validation_errors = array();
445 $validation_errors = validate_siteConfig('b');
446 if(count($validation_errors) > 0) {
453 if($next_step == 9999) {
454 $the_file = 'SilentInstall';
455 }else if($next_step == 9191) {
456 $_SESSION['oc_server_url'] = $_REQUEST['oc_server_url'];
457 $_SESSION['oc_username'] = $_REQUEST['oc_username'];
458 $_SESSION['oc_password'] = $_REQUEST['oc_password'];
459 $the_file = 'oc_convert.php';
462 $the_file = $workflow[$next_step];
470 // Check to see if session variables are working properly
472 $_SESSION['test_session'] = 'sessions are available';
473 @session_write_close();
474 unset($_SESSION['test_session']);
477 if(!isset($_SESSION['test_session']))
479 $the_file = 'installDisabled.php';
480 // PHP.ini location -
481 $phpIniLocation = get_cfg_var("cfg_file_path");
482 $disabled_title = $mod_strings['LBL_SESSION_ERR_TITLE'];
483 $disabled_title_2 = $mod_strings['LBL_SESSION_ERR_TITLE'];
484 $disabled_text = $mod_strings['LBL_SESSION_ERR_DESCRIPTION']."<pre>{$phpIniLocation}</pre>";
487 // check to see if installer has been disabled
488 if(is_readable('config.php') && (filesize('config.php') > 0)) {
489 include_once('config.php');
491 if(!isset($sugar_config['installer_locked']) || $sugar_config['installer_locked'] == true) {
492 $the_file = 'installDisabled.php';
493 $disabled_title = $mod_strings['LBL_DISABLED_DESCRIPTION'];
494 $disabled_title_2 = $mod_strings['LBL_DISABLED_TITLE_2'];
495 $disabled_text =<<<EOQ
496 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION']}</p>
498 'installer_locked' => false,
500 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION_2']}</p>
502 <p>{$mod_strings['LBL_DISABLED_HELP_1']} <a href="{$mod_strings['LBL_DISABLED_HELP_LNK']}" target="_blank">{$mod_strings['LBL_DISABLED_HELP_2']}</a>.</p>
504 //if this is an offline client installation but the conversion did not succeed,
505 //then try to convert again
506 if(isset($sugar_config['disc_client']) && $sugar_config['disc_client'] == true && isset($sugar_config['oc_converted']) && $sugar_config['oc_converted'] == false) {
507 header('Location: index.php?entryPoint=oc_convert&first_time=true');
516 case 'SilentInstall':
518 pullSilentInstallVarsIntoSession();
519 $validation_errors = validate_dbConfig('a');
520 if(count($validation_errors) > 0) {
521 $the_file = 'dbConfig_a.php';
524 $validation_errors = validate_siteConfig('a');
525 if(count($validation_errors) > 0) {
526 $the_file = 'siteConfig_a.php';
529 $validation_errors = validate_siteConfig('b');
530 if(count($validation_errors) > 0) {
531 $the_file = 'siteConfig_b.php';
536 $the_file = 'performSetup.php';
538 //since this is a SilentInstall we still need to make sure that
539 //the appropriate files are writable
541 make_writable('./config.php');
544 make_writable('./custom');
547 recursive_make_writable('./modules');
550 make_writable('./data');
551 make_writable('./data/upload');
554 make_writable('./cache/custom_fields');
555 make_writable('./cache/dyn_lay');
556 make_writable('./cache/images');
557 make_writable('./cache/import');
558 make_writable('./cache/layout');
559 make_writable('./cache/pdf');
560 make_writable('./cache/upload');
561 make_writable('./cache/xml');
563 // check whether we're getting this request from a command line tool
564 // we want to output brief messages if we're outputting to a command line tool
566 if(isset($_REQUEST['cli']) && ($_REQUEST['cli'] == 'true')) {
567 $_SESSION['cli'] = true;
568 // if we have errors, just shoot them back now
569 if(count($validation_errors) > 0) {
570 foreach($validation_errors as $error) {
571 print($mod_strings['ERR_ERROR_GENERAL']."\n");
572 print(" " . $error . "\n");
583 $the_file = clean_string($the_file, 'FILE');
584 // change to require to get a good file load error message if the file is not available.
585 require('install/' . $the_file);